<template>
  <div class="mod-role">
    <el-form :inline="true" :model="dataForm">
      <el-form-item>
        <el-input v-model="dataForm.name" placeholder="商铺名称" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <el-button @click="getDataList()">查询</el-button>
      </el-form-item>
    </el-form>
    <el-table
      :data="dataList"
      border
      v-loading="dataListLoading"
      style="width: 100%;">
       <el-table-column type="expand">
        <template slot-scope="props">
          <el-form label-position="left" inline class="demo-table-expand">
            <div>
            <el-form-item label="账号">
              <span>{{ props.row.username }}</span>
            </el-form-item>
            </div>
            <div>
            <el-form-item label="商户">
              <span>{{ props.row.realname }}</span>
            </el-form-item>
            </div>
            <div>
            <el-form-item label="电话">
              <span>{{ props.row.mobile }}</span>
            </el-form-item>
            </div>
            <div>
            <el-form-item label="店铺地址">
              <span>{{ props.row.province }}{{ props.row.city }}{{ props.row.area }}{{ props.row.street }}</span>
            </el-form-item>
            </div>
          </el-form>
        </template>
      </el-table-column>
      <el-table-column
        prop="shopName"
        header-align="center"
        align="center"
        label="商铺名">
      </el-table-column>
      <el-table-column
        prop="goodsTypeName"
        header-align="center"
        align="center"
        label="主营类目">
      </el-table-column>
      <el-table-column
        prop="isAuth"
        header-align="center"
        align="center"
        label="认证">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.isAuth === 0" size="small" type="danger">未认证</el-tag>
          <el-tag v-if="scope.row.isAuth === 10" size="small" type="danger">认证中</el-tag>
          <el-tag v-if="scope.row.isAuth === 20" size="small" type="success">已认证</el-tag>
          <el-tag v-if="scope.row.isAuth === -10" size="small" type="danger">认证不通过</el-tag>
        </template>
      </el-table-column>
      <el-table-column
        prop="state"
        header-align="center"
        align="center"
        label="状态">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.state === 0" size="small" type="danger">待审核</el-tag>
          <el-tag v-if="scope.row.state === 10" size="small" type="success">正常</el-tag>
          <el-tag v-if="scope.row.state === -10" size="small" type="danger">关闭或审核失败</el-tag>
          <el-tag v-if="scope.row.state === -50" size="small" type="danger">用户关闭店铺</el-tag>
        </template>
      </el-table-column>
      <el-table-column
        prop="createTime"
        header-align="center"
        align="center"
        width="180"
        label="创建时间">
        <template slot-scope="scope">
          {{ scope.row.createTime }}
        </template>
      </el-table-column>
      <el-table-column
        fixed="right"
        header-align="center"
        align="center"
        width="150"
        label="操作">
        <template slot-scope="scope">
          <el-button type="text" size="small" @click="viewInfoHandle(scope.row.cid)">查看</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageIndex"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>
    <shop-manages-view v-if="viewVisible"  ref="shopManagesView" @refreshDataList="getDataList"></shop-manages-view>
   </div>
</template>

<script>
  import ShopManagesView from './shopmanages-view'
  export default {
    data () {
      return {
        dataForm: {
          name: ''
        },
        dataList: [],
        pageIndex: 1,
        pageSize: 10,
        totalPage: 0,
        dataListLoading: false,
        dataListSelections: [],
        viewVisible: false,
        show: false
      }
    },
    components: {
      ShopManagesView
    },
    activated () {
      this.getDataList()
    },
    methods: {
      // 获取数据列表
      getDataList () {
        this.dataListLoading = true
        this.$http({
          url: this.$http.adornUrl('/pig-center-biz/shop/manage/list'),
          method: 'get',
          params: this.$http.adornParams({
            'page': this.pageIndex,
            'limit': this.pageSize,
            'name': this.dataForm.name
          })
        }).then(({data}) => {
          if (data && data.code === 0) {
            this.dataList = data.page.list
            this.totalPage = data.page.totalCount
          } else {
            this.dataList = []
            this.totalPage = 0
          }
          this.dataListLoading = false
        })
      },
      // 每页数
      sizeChangeHandle (val) {
        this.pageSize = val
        this.pageIndex = 1
        this.getDataList()
      },
      // 当前页
      currentChangeHandle (val) {
        this.pageIndex = val
        this.getDataList()
      },
      // 多选
      selectionChangeHandle (val) {
        this.dataListSelections = val
      },
      viewInfoHandle (cid) {
        this.viewVisible = true
        this.$nextTick(() => {
          this.$refs.shopManagesView.init(cid)
        })
      }
    }
  }
</script>
<style>
  .demo-table-expand {
    font-size: 0;
  }
  .demo-table-expand label {
    width: 90px;
    color: #99a9bf;
  }
  .demo-table-expand .el-form-item {
    margin-right: 0;
    margin-bottom: 0;
    width: 50%;
  }
</style>
